<?php

namespace App\Console\Commands\OpenShop;

use App\Models\System\SystemNotifyCenterModel;
use Illuminate\Console\Command;

class SyncSystemNotify extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'sync_system_notify_cityCode';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '同步未发送消息的数据分公司省市区域为ALL';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        SystemNotifyCenterModel::query()
            ->whereRaw('region is null ')
            ->chunk(
                1000, function ($item) {
                foreach ($item as $v) {
                    SystemNotifyCenterModel::query()
                        ->where('id', $v['id'])
                        ->whereRaw('region is null ')
                        ->update(['region' => json_encode('ALL')]);
                }
            }
            );
    }

}
